<?php

require_once dirname(__FILE__).'/../lib/ingresosGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/ingresosGeneratorHelper.class.php';

/**
 * ingresos actions.
 *
 * @package    gescell
 * @subpackage ingresos
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class ingresosActions extends autoIngresosActions
{
    public function executeNew(sfWebRequest $request)
  {
    $this->form = $this->configuration->getForm();
    $this->ingresos = $this->form->getObject();
    $this->form->form2 = new categoria_ingresosForm();
    $this->form->setdefault('sf_guard_user', $this->getUser()->getGuardUser()->getId());

  }
   public function executeEdit(sfWebRequest $request)
  {

    $this->ingresos = $this->getRoute()->getObject();
    $this->form = $this->configuration->getForm($this->ingresos);
    $this->form->form2 = new categoria_ingresosForm();
    
  }
  public function executeAgregartipo(sfWebRequest $request){
            if ($request->isXmlHttpRequest()){
                $this->Form2 = new categoria_ingresosForm();
                $this->procesarForm($request, $this->Form2);
                $form = new ingresosForm();
                //return $this->rendertext('Guardado');
                return $this->renderpartial('ingresos/categoriaingreso1',array('form'=>$form));
            }
        }
  protected function procesarForm(sfWebRequest $request, sfForm $form)
        {
            $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
            if ($form->isValid()){
                $categoria_ingresos = $form->save();
            }

        }
     public function executeDelete(sfWebRequest $request)
  {
    if ($this->getRoute()->getObject()->EsBorrable()){
        $request->checkCSRFProtection();
        $this->dispatcher->notify(new sfEvent($this, 'admin.delete_object', array('object' => $this->getRoute()->getObject())));
        $this->getRoute()->getObject()->delete();
        $this->getUser()->setFlash('notice', 'The item was deleted successfully.');
        $this->redirect('@ingresos');
    }
    else
      $this->redirect('facturas/mensaje?mensaje=Lo sentimos pero la caja esta cerrada y ya no es posible modificar los datos');
  }
  public function executeUpdate(sfWebRequest $request)
  {
    $this->ingresos = $this->getRoute()->getObject();
    if($this->ingresos->esBorrable()){
        $this->form = $this->configuration->getForm($this->ingresos);
        $this->processForm($request, $this->form);
        $this->setTemplate('edit');
    }
    else
      $this->redirect('facturas/mensaje?mensaje=Lo sentimos pero la caja esta cerrada y ya no es posible modificar los datos');

  }
}
